package com.eedi.framework.oauth2.controller.sys;

import com.eedi.framework.common.pojo.CommonResult;
import com.eedi.framework.common.pojo.PageResult;
import com.eedi.framework.oauth2.service.SysAuthService;
import com.eedi.framework.user.controller.sys.vo.SysUserAccountPageReq;
import com.eedi.framework.user.controller.sys.vo.SysUserLoginInfoResp;
import com.eedi.framework.user.service.SysUserService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import io.swagger.v3.oas.annotations.Operation;

import static com.eedi.framework.common.pojo.CommonResult.success;


/**
 * 提供给外部应用调用为主
 *
 * @author 永聚长青源码
 */
@Tag(name = "系统界面 - OAuth2.0 用户")
@RestController
@RequestMapping("/oauth2/user")
@Validated
@Slf4j
public class SysOAuth2UserController {

    @Resource
    private SysUserService sysUserService;

    @Resource
    private SysAuthService sysAuthService;

    @GetMapping("/count")
    @Operation(summary = "获得用户数量")
    @PreAuthorize("@sys.hasPermission('sys:user:count')")
    public CommonResult<Long> count() {
        return success(sysUserService.countUser());
    }

    @GetMapping("/page")
    @Operation(summary = "账号列表")
    @PreAuthorize("@sys.hasPermission('sys:user:query')")
    public CommonResult<PageResult<SysUserLoginInfoResp>> query(SysUserAccountPageReq req) {
        return success(sysAuthService.query(req));
    }


//    @Resource
//    private DeptService deptService;
//
//    @GetMapping("/get")
//    @Operation(summary = "获得用户基本信息")
//    @PreAuthorize("@ss.hasScope('user.read')") //
//    public CommonResult<OAuth2UserInfoRespVO> getUserInfo() {
//        // 获得用户基本信息
//        AdminUserDO user = userService.getUser(getLoginUserId());
//        OAuth2UserInfoRespVO resp = BeanUtils.toBean(user, OAuth2UserInfoRespVO.class);
//        // 获得部门信息
//        if (user.getSystemDeptId() != null) {
//            DeptDO dept = deptService.getDept(user.getSystemDeptId());
//            resp.setDept(BeanUtils.toBean(dept, OAuth2UserInfoRespVO.Dept.class));
//        }
//        return success(resp);
//    }
//
//    @PutMapping("/update")
//    @Operation(summary = "更新用户基本信息")
//    @PreAuthorize("@ss.hasScope('user.write')")
//    public CommonResult<Boolean> updateUserInfo(@Valid @RequestBody OAuth2UserUpdateReqVO reqVO) {
//        // 这里将 UserProfileUpdateReqVO =》UserProfileUpdateReqVO 对象，实现接口的复用。
//        // 主要是，AdminUserService 没有自己的 BO 对象，所以复用只能这么做
//        userService.updateUserProfile(getLoginUserId(), BeanUtils.toBean(reqVO, UserProfileUpdateReqVO.class));
//        return success(true);
//    }

}
